<template>
	<div class="admin-reward" v-if="viewModel">
		<x-border :title="viewModel.moduleConfig.title" type="accent" icon="dicon-5333-biyrer" style="height: 100%;overflow: auto;" :viewModel="viewModel">
			<el-form label-position="right" v-loading="isLoading">
				<el-tabs class="admin-reward_tabs">
					<el-tab-pane>
						<span slot="label" class="tab-pane-span"><i class="el-icon-chat-line-round"></i>基本信息</span>
						<div class="tab-pane-boxs">
							<edit-base :viewModel="viewModel" v-model="viewModel" v-if="viewModel"> </edit-base>
						</div>
					</el-tab-pane>
					<el-tab-pane>
						<span slot="label" class="tab-pane-span"><i class="el-icon-set-up"></i>分润规则</span>
						<div class="tab-pane-boxs">
							<edit-module :viewModel="viewModel" v-if="viewModel" ref="editModule"> </edit-module>
						</div>
					</el-tab-pane>
					<el-tab-pane>
						<span slot="label" class="tab-pane-span"><i class="flaticon-user"></i>用户与等级(限制)</span>
						<div class="tab-pane-boxs">
							<edit-range-user :viewModel="viewModel" v-if="viewModel"></edit-range-user>
						</div>
					</el-tab-pane>
					<el-tab-pane>
						<span slot="label" class="tab-pane-span"><i class="flaticon-analytics"></i>分润范围(限制)</span>
						<div class="tab-pane-boxs">
							<edit-range :viewModel="viewModel" v-if="viewModel"></edit-range>
						</div>
					</el-tab-pane>
					<el-tab-pane v-if="viewModel.moduleConfig.isSupportAssetRules">
						<span slot="label" class="tab-pane-span"><i class="flaticon-coins"></i>资产分配</span>
						<div class="tab-pane-boxs">
							<assets-rule :viewModel="viewModel" v-if="viewModel"></assets-rule>
						</div>
					</el-tab-pane>
				</el-tabs>
				<el-form-item class="form-buttom" label-width="70px">
					<el-button type="primary" @click="dialogVisible = true">保存</el-button>
				</el-form-item>
			</el-form>
			<el-dialog title="保存分润规则" class="reward-edit" :visible.sync="dialogVisible" v-if="viewModel" :append-to-body="true">
				<div class="admin-reward_dialog">
					<div class="modal-body">修改分润规则可能会对市场造成一定的影响，同时可能导致数据出现不可修复的错误。请慎重！保存之前请确保您已详细阅读《服务条款&免责声明》</div>
					<el-form class="reward_dialog-form" @submit.native.prevent>
						<el-form-item label="支付密码" :required="true">
							<el-input type="password" v-model="viewModel.payPassword"></el-input>
						</el-form-item>
					</el-form>
				</div>
				<span slot="footer" class="dialog-footer">
					<el-button @click="dialogVisible = false" class="footer_cancel">取 消</el-button>
					<el-button type="primary" @click="onSubmit" :loading="loading">同意《免责申明》并保存</el-button>
				</span>
			</el-dialog>
		</x-border>
	</div>
</template>
<script>
	import editBase from './widget/edit-base.vue'
	import editModule from './widget/edit-module.vue'
	import editRange from './widget/edit-range.vue'
	import editRangeUser from './widget/edit-range-user.vue'
	import assetsRule from './widget/assets-rule.vue'
	import ala from 'ala'
	export default {
		components: {
			editBase,
			editModule,
			editRange,
			editRangeUser,
			assetsRule
		},
		data() {
			return {
				async: false,
				viewModel: null,
				dialogVisible: false,
				password: '',
				loading: false,
				isLoading: true
			}
		},
		mounted() {
			this.init()
		},
		methods: {
			async init() {
				var para = {
					moduleId: this.$route.query.moduleId,
					id: this.$route.query.id
				}
				var response = await this.$ala.httpGet('api/RewardRule/GetEditView', para)
				if (response) {
					this.viewModel = response
					this.isLoading = false
				}
				if (this.$route.query.copy === 'true' || this.$route.query.copy === true) {
					this.viewModel.id = '000000000000000000000000'
				}
			},
			// 保存
			async onSubmit() {
				this.viewModel.value = JSON.stringify(this.$refs.editModule.$refs.zkAutoForm.viewModel)
				this.loading = true
				var response = await this.$ala.httpPost('api/RewardRule/Save', this.viewModel)
				if (response) {
					this.dialogVisible = false
					this.$ala.toMessage(response)
				}
				this.loading = false
			}
		}
	}
</script>
<style rel="stylesheet/scss" lang="scss">
	@import "./style.scss";
</style>